/**
  ******************************************************************************
  * @file    SmartSwitch_rtc.h
  * @author  sc
  * @date    2017-04-06
  * @brief   RTC
  ******************************************************************************
  */ 

#ifndef __SMART_SWITCH_RTC_H__
#define __SMART_SWITCH_RTC_H__
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "ucos_ii.h"
#include "SmartSwitch_app_cfg.h"

#define SECONDS2000YEAR				946656000	/* ??(2000/01/01 00:00:00)???Linux??(1970/01/01 08:00:00)????? */

#define	IsLeapYear(yr)	(!((yr) % 400) || (((yr) % 100) && !((yr) % 4)))

typedef uint32_t UTCTime;

__packed typedef struct
{
  uint8_t seconds;  // 0-59
  uint8_t minutes;  // 0-59
  uint8_t hour;     // 0-23
  uint8_t day;      // 0-30
  uint8_t month;    // 0-11
  uint16_t year;    // 2000+
} UTCTimeStruct_t;

int32_t SC_RtcSetTime(uint32_t uctSec);
int32_t SC_RtcGetTime(uint32_t *uctSec);
int32_t SC_RtcSoftInit(void);
void SC_RtcHardInit(void);

void SC_ConvertUTCTime( UTCTimeStruct_t *tm, UTCTime secTime );
UTCTime SC_ConvertUTCSecs( UTCTimeStruct_t *tm );
void SC_ConvertStrUTCTime( UTCTimeStruct_t *tm, uint8_t *str );
UTCTime SC_ConvertStrUTCSecs( uint8_t *str );



#endif
